package com.zthz.douxing.sendmessageservice.service

import com.zthz.douxing.TaskInfo
import com.zthz.douxing.event.UserWillDepartEvent
import com.zthz.douxing.msg.MessageType
import grails.transaction.Transactional

@Transactional
class WeatherMessageService extends AbstractHandlerService{

    @Override
    protected String hanldTask(TaskInfo taskInfo) throws Exception {
        String sendResult = null
        UserWillDepartEvent userWillDepartEvent = formateTask2UserWillDepartEvent(taskInfo)
        String message = null
        try{
            message = orderXingeMessageService.orderWeatherMessage(userWillDepartEvent)
            if(isNullMessage(message)){
                sendResult = "ERROR"
                return sendResult
            }
            Map param = geTuiMessageSenderService.getParamFromUserWillDepartEvent4PlanForm(
                    userWillDepartEvent,message,MessageType.WeatherInfo)
            sendResult = geTuiMessageSenderService.send2One(param)
        }catch (Exception e){
            sendResult = "ERROR"
            throw e
        }finally{
            orderXingeMessageService.
                    saveMessageToUserLog(userWillDepartEvent,message,
                            sendResult,MessageType.WeatherInfo)
        }
        return sendResult
    }
}
